package com.pactera.madp.cp.controller.oms.contact;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.pactera.madp.common.core.util.R;
import com.pactera.madp.common.log.annotation.SysLog;
import com.pactera.madp.cp.api.dto.workcontacttag.WorkContactTagGroupAddDTO;
import com.pactera.madp.cp.api.dto.workcontacttag.WorkContactTagGroupUpdateDTO;
import com.pactera.madp.cp.api.vo.ContactTagGroupPageVO;
import com.pactera.madp.cp.api.vo.contact.ContactTagGroupIndexVO;
import com.pactera.madp.cp.service.IWorkContactTagGroupService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author: yangpengwei
 * @time: 2020/12/12 3:19 下午
 * @description 客户标签分组管理
 */
@RestController
@AllArgsConstructor
@RequestMapping("/workcontacttaggroup")
@Api(value = "workcontacttaggroup", tags = "客户标签分组管理")
public class WorkContactTagGroupController {

    IWorkContactTagGroupService workContactTagGroupService;

    /**
     * 分组列表
     */
    @GetMapping("/page")
    @ApiOperation(value = "标签分组列表分页")
    public R<Page<List<ContactTagGroupPageVO>>> getPage(Page page) {
        return R.ok(workContactTagGroupService.getGroupList(page));
    }


    @GetMapping
    @ApiOperation(value = "标签分组列表")
    public R<List<ContactTagGroupIndexVO>> getIndex(){
        return R.ok(workContactTagGroupService.getIndexList());
    }

    /**
     * 分组详情
     */
    @GetMapping("/{groupId}")
    @ApiOperation(value = "标签分组详情")
    @ApiImplicitParams({
            @ApiImplicitParam(name="groupId",value="新标签组id",dataType="Integer")
    })
    public R<ContactTagGroupPageVO> getDetail(@PathVariable Integer groupId) {
        if (groupId == null || groupId <= 0) {
            return R.failed("标签组 Id 无效");
        }

        return R.ok(workContactTagGroupService.getGroupDetail(groupId));
    }

    /**
     * 删除分组
     */
    @SysLog("删除标签分组")
    @DeleteMapping("/{groupId}")
    @ApiOperation(value = "删除标签分组")
    @ApiImplicitParams({
            @ApiImplicitParam(name="groupId",value="待删除的标签组id",dataType="Integer")
    })
    public R<Boolean> deleteGroup(@PathVariable Integer groupId) {
        if (groupId == null || groupId <= 0) {
            return  R.failed(Boolean.FALSE,"标签组 Id 无效");
        }
        return workContactTagGroupService.deleteGroup(groupId)  ? R.ok(Boolean.TRUE,"删除成功"):R.failed(Boolean.TRUE,"删除失败");
    }

    /**
     * 新增分组
     */
    @SysLog("新增标签分组")
    @PostMapping
    @ApiOperation(value = "新增标签分组")
    @ApiImplicitParams({
//            @ApiImplicitParam(name="groupName",value="新标签组名",dataType="String")
    })
    public R<Boolean> createGroup(@RequestBody WorkContactTagGroupAddDTO addDTO) {
        if (addDTO.getGroupName() == null || addDTO.getGroupName().isEmpty()) {
            return  R.failed(Boolean.FALSE,"标签组名称不能为空");
        }
        return workContactTagGroupService.createGroup(addDTO)? R.ok(Boolean.TRUE,"添加成功") : R.failed(Boolean.FALSE,"添加失败");
    }

    /**
     * 编辑分组
     */
    @SysLog("编辑标签分组")
    @PutMapping
    @ApiOperation(value = "编辑标签分组")
    @ApiImplicitParams({
//            @ApiImplicitParam(name="groupId",value="新标签组id",dataType="Integer"),
//            @ApiImplicitParam(name="groupName",value="标签组名",dataType="String"),
//            @ApiImplicitParam(name="isUpdate",value="更新标识，1--更新，非1--不更新",dataType="Integer")
    })
    public R<Boolean> updateGroup(@RequestBody WorkContactTagGroupUpdateDTO updateDTO)  {
        return R.ok(workContactTagGroupService.updateGroup(updateDTO));
    }

}
